Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to filter style properties #200

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

ludovic
Copy link

@ludovic ludovic commented Nov 8, 2024

Added the ability to specify a callback to invoke on each style property when copying, in order to filter the style properties to keep only the desired ones.
This can be interesting to simplify the copied element (removal of the background color for example) or not to keep the CSS variables (as Firefox or Safari does) and thus gain in performance or avoid failures on these browsers.

Sample use:

const filterStyles = (propertyName) {
    return !propertyName.startsWith('--');
}

const wrapper = document.getElementById('wrapper');
const blob =  domtoimage.toBlob(wrapper, { filterStyles: filterStyles});

Fixes #194

Sample use:

```
filterStyles(node, propertyName) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the first parameter node is not passed here. Even though the issue being fix does not require it, I think it's better to include just in case. WDYT?
Or maybe let's fix the README

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch @NogaMan ... I think we should add the node as a parameter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll make the change

@IDisposable
Copy link
Member

Minor issue with the test ignoring the node parameter. I will fix that when cutting the new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter out css variables in Firefox
3 participants